﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace GMS.Client.Core
{
    /// <summary>
    /// 文本框类
    /// </summary>
    public class TextBox : CustomControl
    {
        public TextBox(IntPtr parentHandle, string className, string titleName, CustomControlNameType customControlNameType) : base(parentHandle, className, titleName, customControlNameType) { }

        public TextBox(IntPtr handle, CustomControlNameType customControlNameType) : base(handle, customControlNameType) { }

        /// <summary>
        /// 对文本框赋值
        /// </summary>
        /// <param name="value"></param>
        public void SetValue(object value)
        {
            Win32API.SendMessage_SetValue(base.Handle, (int)WindowsMessageType.WM_SETTEXT, 0, value.ToString());
        }

        /// <summary>
        /// 获取文本框的值
        /// </summary>
        /// <returns></returns>
        public T GetValue<T>()
        {
            var bufferLength = 1024;
            var stringBuilderbuffer = new StringBuilder(bufferLength);
            Win32API.SendMessage_GetValue(base.Handle, (int)WindowsMessageType.WM_GETTEXT, bufferLength, stringBuilderbuffer);
            return (T)Convert.ChangeType(stringBuilderbuffer.ToString(), typeof(T));
        }
    }
}
